package com.cj.bus.common.ex;


import lombok.extern.slf4j.Slf4j;

@Slf4j
public class BaseException extends RuntimeException {
    /**
	 * 
	 */
	private static final long serialVersionUID = -9046763687904403189L;
	private String message;   //传给客户端的
    private Integer exceptionCode;  //异常码，异常类型
    private String exceptionDetail;  //异常详情

    public BaseException(String msg){
        super(msg);
        setMessage(msg);
    }

    public BaseException(Integer code,String msg){
        super(msg);
        setMessage(msg);
        setExceptionCode(code);
    }

    public BaseException(String msg, String detail){
        super(detail);
        setMessage(msg);
        setExceptionDetail(detail);
    }
    
    public BaseException(String msg, Throwable t){
    	super(msg,t);
    	setMessage(msg);
        setExceptionDetail(msg);
    }
    
    public BaseException(Integer code, String msg, String detail){
        this(msg, detail);
        setExceptionCode(code);
    }

    public String getExceptionDetail() {
        return exceptionDetail;
    }

    public void setExceptionDetail(String exceptionDetail) {
        this.exceptionDetail = exceptionDetail;
    }

    public Integer getExceptionCode() {
        return exceptionCode;
    }

    public void setExceptionCode(Integer exceptionCode) {
        this.exceptionCode = exceptionCode;
    }

    @Override
    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public static String printAndSetMsgException(Exception e, String msg){
        if (e instanceof BaseException){
            msg = e.getMessage();
            log.error(((BaseException) e).getExceptionDetail());
        }else {
            log.error("发送错误",e);
        }

        return msg;
    }
}
